// pages/evaluate/evaluateTeacher/evaluateTeacherIndex.js
import { EvaluateModel } from "../../../api/api-evaluate/evaluateModel.js";
import { getWeekDay } from "../../../utils/index.js";
const evaluateModel = new EvaluateModel()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeTab: "first",
    firstPageNum: 1,
    firstTotal: 0,
    firstTableData: [],
    firstTriggered: false,
    firstNoData: false, // 待评价列表有无数据
    secondPageNum: 1,
    secondTotal: 0,
    secondTableData: [],
    secondTriggered: false,
    secondNoData: false, // 待评价列表有无数据
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      firstTriggered: false,
      firstPageNum: 1,
      firstTableData: [],
      secondTriggered: false,
      secondPageNum: 1,
      secondTableData: []
    })
    this.getNotEvaluatedList();
    this.geEvaluatedList();
  },

  // 获取待评价列表
  getNotEvaluatedList() {
    evaluateModel.getNotEvaluatedListApi({ pageNum: this.data.firstPageNum, pageSize: 10 }).then(res => {
      if (res.rows && res.rows.length > 0) {
        res.rows.forEach(item => {
          item['week'] = getWeekDay(item.classDate)
        })
      }
      let datas = this.data.firstTableData;
      datas.push(...res.rows);
      this.setData({
        firstTableData: datas,
        firstTotal: res.total
      })
      if (this.data.firstTableData.length > 0) {
        this.setData({
          firstNoData: false
        })
      }
      else {
        this.setData({
          firstNoData: true
        })
      }
    })
  },
  // 上拉加载
  getFirstMoreData() {
    if (this.data.firstTotal > this.data.firstTableData.length) {
      this.setData({
        firstPageNum: this.data.firstPageNum + 1
      })
      this.getNotEvaluatedList()
    }
  },
  // 下拉刷新
  refreshFirstData() {
    this.setData({
      firstTriggered: false,
      firstPageNum: 1,
      firstTableData: []
    })
    this.getNotEvaluatedList()
  },
  // 去评价
  navigateToEvaluate(e) {
    const param = JSON.stringify(e.currentTarget.dataset.query);
    wx.navigateTo({
      url: `/pages/evaluate/evalauteContent/evaluateContent?param=${param}`,
    })
  },
  // 获取已评价
  geEvaluatedList() {
    evaluateModel.getEvaluatedListApi({ pageNum: this.data.secondPageNum, pageSize: 10 }).then(res => {
      if (res.rows && res.rows.length > 0) {
        res.rows.forEach(item => {
          item['week'] = getWeekDay(item.classDate)
        })
      }
      let datas = this.data.secondTableData;
      datas.push(...res.rows);
      this.setData({
        secondTableData: datas,
        secondTotal: res.total
      })
      if (this.data.secondTableData.length > 0) {
        this.setData({
          secondNoData: false
        })
      }
      else {
        this.setData({
          secondNoData: true
        })
      }
    })
  },
  // 上拉加载
  getSecondMoreData() {
    if (this.data.secondTotal > this.data.secondTableData.length) {
      this.setData({
        secondPageNum: this.data.secondPageNum + 1
      })
      this.geEvaluatedList()
    }
  },
  // 下拉刷新
  refreshSecondData() {
    this.setData({
      secondTriggered: false,
      secondPageNum: 1,
      secondTableData: []
    })
    this.geEvaluatedList()
  },
  // 去评价详情
  navigateToDetail(e) {
    const param = JSON.stringify(e.currentTarget.dataset.query)
    wx.navigateTo({
      url: `/pages/evaluate/evaluateDetail/evaluateDetail?param=${param}`,
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})